package zw_801_900.zw_830_较大分组的位置;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Solution {

    public static void main(String[] args) {
        String s = "abcdddeeeeaabbbcd";
        List<List<Integer>> lists = largeGroupPositions(s);
        for (List<Integer> list : lists) {
            for (Integer integer : list) {
                System.out.println(integer + " ");
            }
            System.out.println();
        }
    }

    public static List<List<Integer>> largeGroupPositions(String s) {
        List<List<Integer>> lists = new ArrayList<>();
        char[] cs = s.toCharArray();
        int i = 0, n = cs.length;
        while (i < n) {
            int count = 0;
            int j = i;
            while (j < n && cs[i] == cs[j]) {
                count++;
                ++j;
            }
            if (count >= 3) lists.add(Arrays.asList(i, j - 1));
            i = j;
        }
        return lists;
    }
}
